package thread.java20230108;

import java.util.Date;
import java.util.concurrent.*;

public class Demo43 {
    public static void main(String[] args) {
        //可以自己创建线程池
        Executor executor = new ThreadPoolExecutor(3,100,1000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
//        //jdk 还提供了一些其他的创建方式
//        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(5);
//
//        executorService.schedule(()->{
//            System.out.println("hello");
//        },1000,TimeUnit.MILLISECONDS);

        ExecutorService executorService = Executors.newFixedThreadPool(3);
        for (int i = 0; i < 10; i++) {
            executorService.submit(()->{
                System.out.println("hello" + new Date());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });

        }
    }
}
